package cn.yoaket.web;

import cn.yoaket.file.DataPhrase;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.locationtech.jts.geom.Polygon;
import cn.yoaket.unit.Edge;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/MapInit")
public class MapInit extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List<Edge> edges = DataPhrase.roadPhrase("D:\\JavaProject\\CoolingPlan\\src\\main\\resources\\road.json");
        List<Polygon> roads = DataPhrase.roadPhrase(edges);
        List<Polygon> buildings = DataPhrase.buildingPhrase("D:\\JavaProject\\CoolingPlan\\src\\main\\resources\\building.json");


        ServletContext context = getServletContext();
        context.setAttribute("roads",roads);
        context.setAttribute("buildings",buildings);
        context.setAttribute("edges",edges);

//        String roadJSON = DataPhrase.toJSON(roads);
//        String buildingJSON = DataPhrase.toJSON(buildings);

//        response.setContentType("text/json");
//        PrintWriter out = response.getWriter();
//        out.print("["+roadJSON+","+buildingJSON+"]");

//        AStar.setNear(edges);

    }
}
